<template>
	<view class="container">
		<uni-section title="图" sub-title="" type="line">
			<image :src="'http://localhost:8090/'+food.icon" mode=""></image>
		</uni-section>
		<uni-section title="名称" sub-title="" type="line">
			<view class="">{{food.name}}</view>
		</uni-section>
		<uni-section title="类别" sub-title="" type="line">
			<view class="">{{food.type}}</view>
		</uni-section>
		<uni-section title="价格" sub-title="" type="line">
			<view class="">{{food.price}}</view>
		</uni-section>
		<uni-section title="描述" sub-title="" type="line">
			<view>{{food.description}}</view>
		</uni-section>
	<view style="display: flex; justify-content: flex-end;">
		<uni-easyinput  v-model="list.comment"/>
		<button type="default" size="mini" @click="pesron">发表</button>
	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				food:{},
				id:'',
				list:{
					
					"foodid": 1,
					"userid": 1,
					"comment": "",
					"postdate": "2022-09-09"
					
				},
				key:''
			}
		},
		methods: {
			get(){
				uni.request({
					url: 'http://localhost:8090/foodapp/food/findone',
					method: 'POST',
					data: {
						id:this.id
					},
					success: res => {
						if(res.data.success){
							this.food=res.data.data
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
		
			pesron(){	
			if(this.key=="ass"){
				uni.request({
					url: 'http://localhost:8090/foodapp/comment/addone',
					method: 'POST',
					data: this.list,
					success: res => {
						if(res.data.success){
							uni.showToast({
								title: '成功',
								icon:"none"
							});
						}
					},
					fail: () => {},
					complete: () => {}
				});
				}else{
					uni.showToast({
						title: '请先登陆',
						icon:"none"
					});
					setTimeout(function(){
						uni.switchTab({
						url:"/pages/my/my"
					})
					},1000)
					
				}
			}
		},
		onLoad: function (option) { 
				 this.id=option.id	 
			},
	    onShow(){
			this.get()
			 this.key=uni.getStorageSync("key")
			 console.log(this.key);
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>
